package com.rjwh.dingdong.client.util;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.rjwh.dingdong.client.R;


public class MyProgressDialog extends Dialog {

    private Context mContext;
    private TextView mMessage;

    public MyProgressDialog(Context context, int theme) {
        super(context, theme);
        mContext = context;
        setContentView(R.layout.myprogressdialog);
        mMessage = (TextView) findViewById(R.id.id_tv_loadingmsg);
        Window wi = getWindow();
        this.setCancelable(false);
        WindowManager.LayoutParams params = wi.getAttributes();
        params.gravity = Gravity.CENTER;

        this.setOnKeyListener(onKeyListener);
    }

    public void setMessage(String temp) {
        mMessage.setText(temp);
    }

    private OnKeyListener onKeyListener = new OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK
                    && event.getAction() == KeyEvent.ACTION_DOWN) {
                dismiss();
            }
            return false;
        }
    };

    @Override
    public void dismiss() {
        try {
            super.dismiss();
        } catch (Exception e) {
        }
    }

}
